package com.ruoyi.supplier.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.supplier.domain.TbPurchaseDetail;
import com.ruoyi.supplier.service.ITbPurchaseDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购明细Controller
 * 
 * @author ruoyi
 * @date 2021-03-05
 */
@RestController
@RequestMapping("/supplier/purchaseDetail")
public class TbPurchaseDetailController extends BaseController
{
    @Autowired
    private ITbPurchaseDetailService tbPurchaseDetailService;

    /**
     * 查询采购明细列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:purchaseDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbPurchaseDetail tbPurchaseDetail)
    {
        startPage();
        List<TbPurchaseDetail> list = tbPurchaseDetailService.selectTbPurchaseDetailList(tbPurchaseDetail);
        return getDataTable(list);
    }

    /**
     * 导出采购明细列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:purchaseDetail:export')")
    @Log(title = "采购明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbPurchaseDetail tbPurchaseDetail)
    {
        List<TbPurchaseDetail> list = tbPurchaseDetailService.selectTbPurchaseDetailList(tbPurchaseDetail);
        ExcelUtil<TbPurchaseDetail> util = new ExcelUtil<TbPurchaseDetail>(TbPurchaseDetail.class);
        return util.exportExcel(list, "purchaseDetail");
    }

    /**
     * 获取采购明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('supplier:purchaseDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbPurchaseDetailService.selectTbPurchaseDetailById(id));
    }

    /**
     * 新增采购明细
     */
    @PreAuthorize("@ss.hasPermi('supplier:purchaseDetail:add')")
    @Log(title = "采购明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbPurchaseDetail tbPurchaseDetail)
    {
        return toAjax(tbPurchaseDetailService.insertTbPurchaseDetail(tbPurchaseDetail));
    }

    /**
     * 修改采购明细
     */
    @PreAuthorize("@ss.hasPermi('supplier:purchaseDetail:edit')")
    @Log(title = "采购明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbPurchaseDetail tbPurchaseDetail)
    {
        return toAjax(tbPurchaseDetailService.updateTbPurchaseDetail(tbPurchaseDetail));
    }

    /**
     * 删除采购明细
     */
    @PreAuthorize("@ss.hasPermi('supplier:purchaseDetail:remove')")
    @Log(title = "采购明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbPurchaseDetailService.deleteTbPurchaseDetailByIds(ids));
    }
}
